package com.dongdongshop.service.impl;

import com.alibaba.dubbo.config.annotation.Service;
import com.dongdongshop.front.pojo.AddressVo;
import com.dongdongshop.front.pojo.TbAddress;
import com.dongdongshop.front.service.AddressService;
import com.dongdongshop.mapper.TbAddressMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Component
@Service
@Transactional
public class AddressServiceImpl implements AddressService {

    @Autowired
    private TbAddressMapper addressMapper;

    @Override
    public List<AddressVo> getAddressByUsername(String username) {
        List<AddressVo> addressVos = addressMapper.getAddressByUsername(username);
        return addressVos;
    }

    @Override
    public void addAdress(TbAddress address) {
        addressMapper.insertSelective(address);
    }

    @Override
    public void updateAdressById(TbAddress address) {
        addressMapper.updateByPrimaryKeySelective(address);
    }

    @Override
    public TbAddress getAddressById(Long id) {
        TbAddress tbAddress = addressMapper.selectByPrimaryKey(id);
        return tbAddress;
    }

    @Override
    public void deleteById(Long id) {
        addressMapper.deleteByPrimaryKey(id);
    }

    @Override
    public AddressVo getAddressVoByAddressId(Long id) {
        AddressVo addressVo = addressMapper.getAddressVoByAddressId(id);
        return addressVo;
    }
}
